package base.day22.stream;

import java.util.ArrayList;
import java.util.function.Consumer;
import java.util.stream.Stream;

public class MyStream4 {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<>();
        list.add("aaa");
        list.add("aaa");
        list.add("abc");
        list.add("ccc");
        list.add("acd");
        list.add("ccc");

        //limit 截取指定参数的个数
        list.stream().limit(3).forEach(s-> System.out.println(s));
        System.out.println("--------------------------------------------");
        //skip 跳过指定参数个数的数据
        list.stream().skip(3).forEach(s-> System.out.println(s));
        //concat(stream1,stream2) 合并a b 两个流为一个流
        System.out.println("--------------------------------------------");
        ArrayList<String> newlist=new ArrayList<>();
        newlist.add("111");
        newlist.add("222");
        newlist.add("333");
        newlist.add("333");
        newlist.add("444");
        newlist.add("555");
//        Stream<String> stream1 = list.stream();
//        Stream<String> stream2 = newlist.stream();
        Stream.concat(list.stream(),newlist.stream()).forEach(s-> System.out.println(s));
        System.out.println("----------------------------------------------");

        //distinct 去除流中重复的元素 依赖hashcode和equals方法
        list.stream().distinct().forEach(s-> System.out.println(s));
        System.out.println("-----------------------------------------------");


        //foreach (Consumer action)
        list.stream().forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });
        //long count返回流中的元素个数
        long count = list.stream().count();
        System.out.println(count);

    }
}
